import odoo.http as http
from odoo.http import Response
import logging

_logging = logging.getLogger(__name__)


class StuInfoController(http.Controller):
    @http.route('/sign_up/stu_info/test', type='json', auth='public', methods=['POST'], website=True)
    def test(self, **args):
        _logging.info('CONNECTION SUCCESSFUL')
        _logging.info(args)
        name = args.get('name', False)
        email = args.get('email', False)
        _logging.info(name)
        _logging.info(email)
        if not name:
            Response.status = '400 Bad Request'
        return '{"response": "OK"}'

    @http.route('/sign_up/stu_info/all', type='json', auth='public', methods=['POST'], website=True)
    def get_all(self, **args):
        _logging.info('CONNECTION SUCCESSFUL')
        # _logging.info(args)
        stu = http.request.env['stu.info'].sudo()
        stus = stu.search([]).mapped("name")
        # stus = stu.search([]).mapped("name")
        # search_read(self, model, fields=False, offset=0, limit=False, domain=None, sort=None)
        _logging.info(stus)
        return {
            'students': stus
        }

    # order = request.env['sale.order'].sudo().browse(sale_order_id).exists()
    # assert order.id == request.session.get('sale_last_order_id')
    #
    # return {
    #     'recall': order.get_portal_last_transaction().state == 'pending',
    #     'message': request.env['ir.ui.view'].render_template("website_sale.payment_confirmation_status", {
    #         'order': order
    #     })
    # }
